package cn.wolfcode.trip.admin.controller;

import cn.wolfcode.trip.base.domain.Goods;
import cn.wolfcode.trip.base.query.GoodsQueryObject;
import cn.wolfcode.trip.base.service.IGoodStyleService;
import cn.wolfcode.trip.base.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private IGoodsService goodsService;
    @Autowired
    private IGoodStyleService goodStyleService;

    @RequestMapping("/list")
    public String list(@ModelAttribute("qo") GoodsQueryObject qo, Model model) {
        qo.setPageSize(5);
        model.addAttribute("pageInfo", goodsService.query(qo));
        model.addAttribute("goodStyles", goodStyleService.list());
        return "goods/list";
    }

    @RequestMapping("/saveOrUpdate")
    public String saveOrUpdate(Goods entity) {
        goodsService.saveOrUpdate(entity);
        return "redirect:/goods/list.do";
    }

    /**
     * 根据大攻略的id查询可用的攻略分类
    @RequestMapping("/listByStrategyId")
    @ResponseBody
    public Object listByStrategyId(Long strategyId) {
        return goodsService.list(strategyId);
    }*/
}
